import numpy as np
import scipy.stats as stats
import statsmodels.stats.api as sms

# 生成模拟数据
np.random.seed(42)
data_A = np.random.normal(5.0, 1.5, 30)
data_B = np.random.normal(5.5, 1.5, 30)

# --- 计算均值的 95% 置信区间 ---
confidence_level = 0.95
ci = stats.t.interval(confidence_level, len(data_A)-1,
                     loc=np.mean(data_A),
                     scale=stats.sem(data_A))
print(f"均值置信区间: {ci}")

# --- 独立样本 t 检验 ---
t_stat, p_value = stats.ttest_ind(data_A, data_B)
print(f"t 统计量: {t_stat:.3f}, p 值: {p_value:.3f}")
